 <?php 
  try {  	
  $form = $_POST['form'];
  
  $EmployeeUid = $form['EMPLOYEE_UID'];
  $Employeefirstname = strtoupper($form['EMPLOYEEFIRSTNAME']);
  $Employeemiddlename = strtoupper($form['EMPLOYEEMIDDLENAME']);
  $Employeelastname = strtoupper($form['EMPLOYEELASTNAME']);
  $Employeecalledname = $form['EMPLOYEECALLEDNAME'];
  $Employeeworkemail = $form['EMPLOYEEWORKEMAIL'];
  $Employeepersonalemail = $form['EMPLOYEEPERSONALEMAIL'];
  $Employeehomephone = $form['EMPLOYEEHOMEPHONE'];
  $Employeemobilephone = $form['EMPLOYEEMOBILEPHONE'];
  $Employeewebpage = $form['EMPLOYEEWEBPAGE'];
  $EmployeegenderId = $form['EMPLOYEEGENDER_ID'];
  $Employeedateofbirth = $form['EMPLOYEEDATEOFBIRTH'];
  $EmployeestateId = $form['EMPLOYEESTATE_ID'];
  $Employeessn = $form['EMPLOYEESSN'];
  $Employeepicture = $form['EMPLOYEEPICTURE'];
  $Employeeishispanic = $form['EMPLOYEEISHISPANIC'];
  $Employeeisasian = $form['EMPLOYEEISASIAN'];
  $Employeeisafricanamerican = $form['EMPLOYEEISAFRICANAMERICAN'];
  $Employeeisamericanindian = $form['EMPLOYEEISAMERICANINDIAN'];
  $Employeeisalaskanative = $form['EMPLOYEEISALASKANATIVE'];
  $Employeeishawaiianorotherpacificislander = $form['EMPLOYEEISHAWAIIANOROTHERPACIFICISLANDER'];
  $Employeeiswhite = $form['EMPLOYEEISWHITE'];
  $DistrictId = $form['DISTRICT_ID'];
  $Districtphone = $form['DISTRICTPHONE'];
  $Districtextension = $form['DISTRICTEXTENSION'];
  $Homephoneunlisted = $form['HOMEPHONEUNLISTED'];
  $MaritalstatusId = $form['MARITALSTATUS_ID'];
  $Subdays = $form['SUBDAYS'];
  $Osdidistrictcode = $form['OSDIDISTRICTCODE'];
  $Directdepost = $form['DIRECTDEPOST'];
  $Retirementeligible = $form['RETIREMENTELIGIBLE'];
  $Handicapstatus = $form['HANDICAPSTATUS'];
  $Multilingual = $form['MULTILINGUAL'];
  $Reporttoemis = $form['REPORTTOEMIS'];
  $Odhsreported = $form['ODHSREPORTED'];
//  $EmployeetypeId = $form['EMPLOYEETYPE_ID'];
  $Emisemployeeid = $form['EMISEMPLOYEEID'];
  $Emaildirectdepost = $form['EMAILDIRECTDEPOST'];

  require_once ( PATH_PLUGINS . 'hr' . PATH_SEP . 'class.hr.php');
  $pluginObj = new hrClass ();

  require_once ( "classes/model/HrEmployee.php" );
     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = HrEmployeePeer::retrieveByPK( $EmployeeUid );
     if ( ! ( is_object ( $tr ) &&  get_class ($tr) == 'HrEmployee' ) ) {
       $tr = new HrEmployee();
     }
     $tr->setEmployeeUid( $EmployeeUid );
     $tr->setEmployeefirstname( $Employeefirstname );
     $tr->setEmployeemiddlename( $Employeemiddlename );
     $tr->setEmployeelastname( $Employeelastname );
     $tr->setEmployeecalledname( $Employeecalledname );
     $tr->setEmployeeworkemail( $Employeeworkemail );
     $tr->setEmployeepersonalemail( $Employeepersonalemail );
     $tr->setEmployeehomephone( $Employeehomephone );
     $tr->setEmployeemobilephone( $Employeemobilephone );
     $tr->setEmployeewebpage( $Employeewebpage );
     $tr->setEmployeegenderId( $EmployeegenderId );
     $tr->setEmployeedateofbirth( $Employeedateofbirth );
     $tr->setEmployeestateId( $EmployeestateId );
     $tr->setEmployeessn( $Employeessn );
     $tr->setEmployeepicture( $Employeepicture );
     $tr->setEmployeeishispanic( $Employeeishispanic );
     $tr->setEmployeeisasian( $Employeeisasian );
     $tr->setEmployeeisafricanamerican( $Employeeisafricanamerican );
     $tr->setEmployeeisamericanindian( $Employeeisamericanindian );
     $tr->setEmployeeisalaskanative( $Employeeisalaskanative );
     $tr->setEmployeeishawaiianorotherpacificislander( $Employeeishawaiianorotherpacificislander );
     $tr->setEmployeeiswhite( $Employeeiswhite );
     $tr->setDistrictId( $DistrictId );
     $tr->setDistrictphone( $Districtphone );
     $tr->setDistrictextension( $Districtextension );
     $tr->setHomephoneunlisted( $Homephoneunlisted );
     $tr->setMaritalstatusId( $MaritalstatusId );
     $tr->setSubdays( $Subdays );
     $tr->setOsdidistrictcode( $Osdidistrictcode );
     $tr->setDirectdepost( $Directdepost );
     $tr->setRetirementeligible( $Retirementeligible );
     $tr->setHandicapstatus( $Handicapstatus );
     $tr->setMultilingual( $Multilingual );
     $tr->setReporttoemis( $Reporttoemis );
     $tr->setOdhsreported( $Odhsreported );
//     $tr->setEmployeetypeId( $EmployeetypeId );
     $tr->setEmisemployeeid( $Emisemployeeid );
     $tr->setEmaildirectdepost( $Emaildirectdepost );

     // rme added 
     /* 
     // rme comment
     $_usr     = strtolower($form['EMPLOYEELASTNAME']);
     $_pwd     = '123456';
     $_first   = strtoupper($form['EMPLOYEEFIRSTNAME']);
     $_last    = strtoupper($form['EMPLOYEELASTNAME']);
     $_email   = strtolower($form['EMPLOYEEPERSONALEMAIL']);
     $_rol     = '00000000000000000000000000000003';

     require_once 'classes/class.pmFunctions.php';

     $tt = PMFCreateUser($_usr, $_pwd, $_first, $_last, $_email, $_rol);

     $con2 = Propel::getConnection('workflow');
     $sql2 = "SELECT USR_UID 
             FROM USERS 
             WHERE USR_USERNAME = '" . $_usr . "'";
     $stmt2 = $con2->createStatement();
     $rs2 = $stmt2->executeQuery($sql2, ResultSet::FETCHMODE_ASSOC);
     $rs2->next();
     $tupla2 = $rs2->getRow();

     $UserUid = $tupla2['USR_UID'];
     // rme end

     $tr->setUserId( $UserUid );
     // rme coment end
     */

     if ($tr->validate() ) {
       // we save it, since we get no validation errors, or do whatever else you like.
       $res = $tr->save();
     }
     else {
       // Something went wrong. We can now get the validationFailures and handle them.
       $msg = '';
       $validationFailuresArray = $tr->getValidationFailures();
       foreach($validationFailuresArray as $objValidationFailure) {
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       }
       //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
     }
    //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');

    //to do: uniform  coderror structures for all classes

  //if ( $res['codError'] < 0 ) {
  //  G::SendMessageText ( $res['message'] , 'error' );
  //}

  G::Header('location: hrEmployeeEditSS');

  }
  catch ( Exception $e ) {
    $G_PUBLISH = new Publisher;
    $aMessage['MESSAGE'] = $e->getMessage();
    $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
    G::RenderPage( 'publish', 'blank' );
  }


function create_user($form) {

try {
  global $RBAC;

    $_usr     = $form['EMPLOYEELASTNAME'];
    $_pwd     = md5('123456');
    $_first   = $form['EMPLOYEEFIRSTNAME'];
    $_last    = $form['EMPLOYEELASTNAME'];
    $_email   = $form['EMPLOYEEPERSONALEMAIL'];
    $_rol     = 'PROCESSMAKER_OPERATOR';

    require_once 'classes/class.pmFunctions.php';

    $aData['USR_USERNAME']    = $_usr;
    $aData['USR_PASSWORD']    = $_pwd;
    $aData['USR_FIRSTNAME']   = $form['EMPLOYEEFIRSTNAME'];
    $aData['USR_LASTNAME']    = $form['EMPLOYEELASTNAME'];
    $aData['USR_EMAIL']       = 'employee@gmail.com';
    $aData['USR_DUE_DATE']    = '2012/01/01';
    $aData['USR_CREATE_DATE'] = date('Y-m-d H:i:s');
    $aData['USR_UPDATE_DATE'] = date('Y-m-d H:i:s');
    $aData['USR_BIRTHDAY']    = date('Y-m-d');
    $aData['USR_AUTH_USER_DN'] = $_auth;
    //fixing bug in inactive user when the admin create a new user.
    $aData['USR_STATUS']      = 1;
    $sUserUID                 = $RBAC->createUser( $aData, $_rol );

    $aData['USR_STATUS']      = $_status2;
    $aData['USR_UID']         = $sUserUID;
    $aData['USR_PASSWORD']    = $_pwd;
    
    $aData['USR_COUNTRY']     = ' ';
    $aData['USR_CITY']        = ' ';
    $aData['USR_LOCATION']    = ' ';
    $aData['USR_ADDRESS']     = ' ';
    $aData['USR_PHONE']       = ' ';
    $aData['USR_ZIP_CODE']    = ' ';
    $aData['USR_POSITION']    = ' ';
    $aData['USR_RESUME']      = ' ';
    
    $aData['USR_ROLE']        = $_rol;
    
    $aData['USR_REPLACED_BY'] = $form['USR_REPLACED_BY'];
    
    
    require_once 'classes/model/Users.php';
    $oUser = new Users();
    return ( $oUser->create( $aData ) );
}

catch (Exception $e) {
  $G_MAIN_MENU            = 'processmaker';
  $G_SUB_MENU             = 'users';
  $G_ID_MENU_SELECTED     = 'USERS';
  $G_ID_SUB_MENU_SELECTED = '';
  
  $aMessage = array();
  $aMessage['MESSAGE'] = $e->getMessage();
  $G_PUBLISH          = new Publisher;
  $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
  G::RenderPage( 'publish');
}

}

